//
//  MyScore.m
//  Find the difference
//
//  Created by administrator on 16/8/14.
//  Copyright © 2016年 duanzhenglong. All rights reserved.
//

#import "MyScore.h"
#import "SldeSlipMenu.h"
#import "Menu.h"
#import "GameBegain.h"
#import "AppDelegate.h"
@interface MyScore ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *TableView;
- (IBAction)Back:(UIButton *)sender;
- (IBAction)Clear:(UIButton *)sender;
@property(nonatomic,strong)NSMutableArray*DataArray;
@end

@implementation MyScore

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
- (IBAction)Back:(UIButton *)sender {
    GameBegain*G1=[[GameBegain alloc]init];
    Menu*M1=[[Menu alloc]init];
    SldeSlipMenu*S1=[[SldeSlipMenu alloc]initWithView:M1 andMainView:G1];
    S1.sideslipTapGes.enabled=YES;
    [self presentViewController:S1 animated:YES completion:nil];
}

- (IBAction)Clear:(UIButton *)sender {
    NSString*path=[NSString stringWithFormat:@"%@/Documents/myScore.plist",NSHomeDirectory()];
    NSMutableArray*arr=[NSMutableArray arrayWithContentsOfFile:path];
    [arr removeAllObjects];
    [arr writeToFile:path atomically:YES];
    [self.TableView reloadData];
}

-(NSMutableArray *)DataArray{
    if (_DataArray==nil) {
        NSString*path=[NSString stringWithFormat:@"%@/Documents/myScore.plist",NSHomeDirectory()];
        NSArray*Arr=[NSArray arrayWithContentsOfFile:path];
        _DataArray=[NSMutableArray array];
        [_DataArray addObjectsFromArray:[[Arr reverseObjectEnumerator]allObjects]];
    }
    return _DataArray;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.DataArray.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    [[cell viewWithTag:11] removeFromSuperview];
    AppDelegate*del=[[UIApplication sharedApplication]delegate];
    cell.detailTextLabel.text=[self.DataArray[indexPath.row]objectForKey:@"score"];
    cell.textLabel.text=del.NAME;
    UILabel*TimeLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 190, 80)];
    TimeLabel.center=CGPointMake(cell.frame.size.width/2+20, cell.frame.size.height/2+10);
    TimeLabel.text=[self.DataArray[indexPath.row] objectForKey:@"time"];
    TimeLabel.tag=11;
    TimeLabel.textColor=[UIColor blackColor];
    [cell addSubview:TimeLabel];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    NSString*str=@"最近战况：";
    return str;
}
@end
